package gzj.service.moment;

import gzj.mapper.moment.MomentMapper;
import gzj.pojo.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author ☞☞ 祝晨轩
 * @DateTime ☞☞ 2019/7/13 8:25
 * 不积跬步，无以至千里；不积小流，无以成江海。
 * 键盘敲烂，月薪过万。
 */
@Service
public class MomentServiceImpl implements MomentService{
    @Resource
    private MomentMapper momentMapper;
    @Override
    public List<Moment> selectMomentList(PageSupport pageSupport) {
        HashMap map=new HashMap();
        map.put("begin",(pageSupport.getCurrentPageNo()-1)*pageSupport.getPageSize());
        map.put("pageSize",pageSupport.getPageSize());
        return this.momentMapper.selectMomentList(map);
    }
    @Override
    public int getCountBySchoolAndCategory(int school_id, int category_id) {
        return this.momentMapper.getMomentCountBySchoolAndCategory(school_id,category_id);
    }
    @Override
    public List<School> getSchoolList() {
        return this.momentMapper.getSchoolList();
    }
    @Override
    public List<Category> getCategoryList() {
        return this.momentMapper.getCategoryList();
    }
    @Override
    public String getCategoryByCategory_id(int category_id) {
        return this.momentMapper.getCategoryByCategory_id(category_id);
    }
    @Override
    public String getSchoolBySchool_id(int school_id) {
        return this.momentMapper.getSchoolBySchool_id(school_id);
    }
    @Override
    public int addLike(int moment_id) {
        return this.momentMapper.addLike(moment_id);
    }
    @Override
    public List<Moment> getMomentListBySchool(int school_id, PageSupport pageSupport) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("school_id",school_id);
        map.put("begin",(pageSupport.getCurrentPageNo()-1)*pageSupport.getPageSize());
        map.put("pageSize",pageSupport.getPageSize());
        //System.out.println(1/0);
        return this.momentMapper.getMomentListBySchool(map);
    }
    @Override
    public List<Moment> getMomentListByCategory(int category_id, PageSupport pageSupport) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("category_id",category_id);
        map.put("begin",(pageSupport.getCurrentPageNo()-1)*pageSupport.getPageSize());
        map.put("pageSize",pageSupport.getPageSize());
        //System.out.println(1/0);
        return this.momentMapper.getMomentListByCategory(map);
    }

    @Override
    public int addMoment(int category_id, int school_id, String userName, String content,String img) {
        Moment moment=new Moment();
        moment.setSchool_id(school_id);
        moment.setCategory_id(category_id);
        moment.setAuthor(userName);
        moment.setContent(content);
        moment.setImg(img);
        return this.momentMapper.addMoment(moment);
    }

    @Override
    public int del(int school_id) {
        return this.momentMapper.del(school_id);
    }

    @Override
    public int addCommenNum(int moment_id) {
        return this.momentMapper.addCommenNum(moment_id);
    }

    @Override
    public int addCommen(int moment_id, String content, String commenter) {
        MomentComment momentComment=new MomentComment();
        momentComment.setMoment_id(moment_id);
        momentComment.setContent(content);
        momentComment.setCommenter(commenter);
        return this.momentMapper.addCommen(momentComment);
    }

    @Override
    public List<MomentComment> seletComment(int moment_id) {
        return this.momentMapper.selectComment(moment_id);
    }

    @Override
    public Moment getMoment(int moment_id) {
        return this.momentMapper.getMoment(moment_id);
    }

    @Override
    public List<Moment> getMomentByUid(int uid) {
        return this.momentMapper.getMomentByUid(uid);
    }

    public List<Moment> getMomentList(int category_id,int school_id,PageSupport pageSupport){
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("category_id",category_id);
        map.put("school_id",school_id);
        map.put("begin",(pageSupport.getCurrentPageNo()-1)*pageSupport.getPageSize());
        map.put("pageSize",pageSupport.getPageSize());
        //System.out.println(1/0);
        return this.momentMapper.getMomentList(map);
    }

}
